home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / dbms_mag / 9102 / foxpro1.feb < prev    next >
Text File  |  1990-12-19  |  3KB  |  143 lines

  1.  
  2. ************************************************************
  3. * Program ...: FixDBT.prg
  4. * Author ....: P. L. Olympia, Platinum Software Int'l
  5. * Purpose....: Converts a Clipper memo file to FoxPro by
  6. *            : (1) Replacing CHR(141) with space
  7. *            : (2) Packing the file by removing blank data
  8. * Notes .....: This generic FoxPro program will convert all
  9. *            : memo fields in the file. Uses FoxPro
  10. *            : low-level file I/O and indirect file ref.
  11. ************************************************************
  12.  
  13. SET TALK OFF
  14. SET SAFE OFF
  15. CLEA ALL
  16. CLOS ALL
  17.  
  18. PrimName = SPAC(25)
  19. CLEA
  20. TEXT
  21.  
  22.            CONVERT CLIPPER MEMO FILE TO FOXPRO
  23.                       
  24. This program converts all soft returns to spaces in Clipper
  25. memo fields so that FoxPro does not delete them and cause
  26. words from two successive lines to run into each other.
  27.      
  28. At the prompt below, supply the name of the Clipper .dbt
  29. file to be converted. This file will be renamed with the
  30. extension of .old. You may supply a fully qualified name
  31. including path but do NOT include the .dbt extension
  32. (Example: C:\APERS\PE).
  33.      
  34. ENDT
  35. @ 20, 0 SAY "Name of .dbt file to convert" GET PrimName
  36. READ
  37.  
  38. PrimName = ALLTRIM(PrimName)
  39. IF AT(".", PrimName) = 0
  40.    new_dbt = PrimName + ".DBT"
  41. ELSE    && just in case jokers added the extension anyway
  42.    new_dbt = PrimName
  43.    PrimName = STUFF(PrimName, AT(".",PrimName), 4, "")
  44. ENDIF
  45.      
  46. * old_dbt = STUFF(new_dbt, AT(".",new_dbt)+1, 3, "OLD")
  47. old_dbt = PrimName + ".OLD"
  48. bytesize = 2000
  49. bytew = 0
  50.  
  51. IF FILE(old_dbt)
  52.   COPY FILE (new_dbt) TO (old_dbt)
  53. ELSE
  54.   RENAME (new_dbt) TO (old_dbt)
  55. ENDIF
  56.  
  57. CLEA  
  58. fh_in = FOPEN(old_dbt)
  59. IF fh_in < 0
  60.   ? CHR(7), old_dbt, " cannot be opened. Aborting."
  61.   RETU
  62. ENDIF
  63.  
  64. fh_out = FCREATE(new_dbt)
  65.  
  66. str = FREAD(fh_in, 512)         && read & write header
  67. byte = FWRITE(fh_out, str)
  68.  
  69. DO WHILE !FEOF(fh_in)
  70.    str = FREAD(fh_in, bytesize)
  71.    oldstr = SUBS(str,1, 512)
  72.    str = STRTRAN(str, CHR(141), CHR(32))  && repl soft retn
  73.    byte = FWRITE(fh_out, str)
  74.    IF byte = 0
  75.       ? CHR(7), "Error writing to ", new_dbt
  76.    ENDIF
  77.    bytew = bytew + byte
  78.    @ 10, 10 SAY "Bytes written thus far" 
  79.    @ 10, 40 SAY bytew
  80. ENDDO
  81.  
  82. ***** PART 2 *****
  83.  
  84. *-- Next, replace all memo field values which are just
  85. *-- whitespace with nulls. Need to cycle thru all memo
  86. *-- fields in the file
  87.  
  88. CLEA
  89. CLOSE ALL
  90.  
  91. * Get rid of any existing .fpt file
  92. str = PrimName + ".FPT"
  93. IF FILE(str)
  94.    DELE FILE (str)
  95. ENDIF
  96.  
  97. USE (PrimName) in 1
  98. COPY STRU EXTE TO $temp
  99. SELE 2
  100. USE $temp    && in 2
  101.  
  102. @ 10, 0 SAY "Getting rid of blank memo field data ..."
  103. *   Look for all memo fields and replace with nulls
  104. SCAN
  105.   IF field_type = "M"
  106.      mf = field_name
  107.      SELE 1
  108.     REPL ALL &mf WITH "" FOR LEN(TRIM(&mf)) = 0
  109.   ENDIF
  110.   SELE 2
  111. ENDSCAN
  112. USE IN 2
  113.  
  114. CLEA
  115. @ 10, 0 SAY "File cleanup in progress ..."
  116. *   Now we need to copy the file to purge all the nulls
  117. SELE 1
  118. COPY TO $temp
  119. CLOSE ALL
  120.  
  121. IF .f.
  122. DELE FILE (new_dbt)
  123. new_dbt = PrimName + ".FPT"
  124. COPY FILE $temp.fpt TO (new_dbt)
  125. DELE FILE $temp.dbf
  126. DELE FILE $temp.fpt
  127. ENDIF
  128.  
  129. str = PrimName + ".DBF"
  130. DELE FILE (str)
  131. RENAME $temp.dbf TO (str)
  132. new_dbt = PrimName + ".FPT"
  133. RENAME $temp.fpt TO (new_dbt)
  134. CLEA
  135.  
  136. * Ending stuff
  137. CLOSE ALL
  138. SET TALK ON
  139. SET SAFE ON
  140. RETU
  141. *-- eof, FixDbt.Prg
  142.  
  143.